package ynu.edu.auth.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import ynu.edu.auth.service.PermissionService;

import java.util.List;

@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
@Api(tags = "权限服务")
public class PermissionController {

    private final PermissionService permissionService;

    // 查询权限
    @GetMapping("/permissions")
    @ApiOperation("查询权限")
    public List<String> getPermissions(@RequestParam("userId") Long userId) {
        return permissionService.getPermissions(userId);
    }

    // 查询角色
    @GetMapping("/roles")
    @ApiOperation("查询角色")
    public List<String> getRoles(@RequestParam("userId") Long userId) {
        return permissionService.getRoles(userId);
    }

    // 分配默认角色
    @PostMapping("/default-role")
    @ApiOperation("分配默认角色")
    public void assignDefaultRole(@RequestParam("userId") Long userId) {
        permissionService.assignDefaultRole(userId);
    }

}
